package com.tianyuan.dplrf.ui.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.hjq.widget.layout.WrapRecyclerView;
import com.tianyuan.dplrf.R;
import com.tianyuan.dplrf.ui.activity.Minenc_jtActivity;
import com.tianyuan.dplrf.ui.activity.PayLandActivity;
import com.tianyuan.dplrf.ui.adapter.NcjtZmAdapter;
import com.tianyuan.dplrf.ui.bean.NcjtzhongmBean;

import java.util.ArrayList;
import java.util.List;

public class FragmentN2 extends FragmentLandBase implements View.OnClickListener {
    private WrapRecyclerView recyview;
    private NcjtZmAdapter mAdapter;
    private List<NcjtzhongmBean> mlist;
    private AppCompatImageView img_item;
    private TextView tv_item_name;
    private TextView tv_item_price;
    private TextView tv_detitl;
    private NestedScrollView nestscroll;
    private Button btn_xiadan;
    private LinearLayout linear_detil;

    public static FragmentN2 newInstance() {
        return new FragmentN2();
    }
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_ncjt_zmlayout;
    }

    @Override
    protected void initView() {
        img_item = (AppCompatImageView) findViewById(R.id.img_item);
        tv_item_name = (TextView) findViewById(R.id.tv_item_name);
        tv_item_price = (TextView) findViewById(R.id.tv_item_price);
        tv_detitl = (TextView) findViewById(R.id.tv_detitl);
        nestscroll = (NestedScrollView) findViewById(R.id.nestscroll);
        btn_xiadan = (Button) findViewById(R.id.btn_xiadan);
        linear_detil = (LinearLayout) findViewById(R.id.linear_detil);
        btn_xiadan.setOnClickListener(this);
        recyview = (WrapRecyclerView) findViewById(R.id.recyview);
        mAdapter = new NcjtZmAdapter(getApplication());
        setData();
        mAdapter.setData(mlist);
        mAdapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
                recyview.setVisibility(View.GONE);
                linear_detil.setVisibility(View.VISIBLE);
            }
        });
        recyview.setLayoutManager(new LinearLayoutManager(getApplication(),RecyclerView.VERTICAL,false));
        recyview.setAdapter(mAdapter);

        recyview.setVisibility(View.VISIBLE);
        linear_detil.setVisibility(View.GONE);


    }

    private void setData() {
        mlist = new ArrayList<>();
        addData(R.drawable.img_zm1,"白菜苗");
        addData(R.drawable.img_zm2,"东瓜苗");

        addData(R.drawable.img_zm1,"白菜苗");
        addData(R.drawable.img_zm2,"东瓜苗");

        addData(R.drawable.img_zm1,"白菜苗");
    }

    private void addData(int icSunrise, String name) {
        NcjtzhongmBean bean = new NcjtzhongmBean();
        bean.setImgid(icSunrise);
        bean.setName(name);
        mlist.add(bean);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onBackClick() {
        if (recyview.getVisibility() == View.VISIBLE){
            ((Minenc_jtActivity)getActivity()).onPopfinish();
        }else {
            recyview.setVisibility(View.VISIBLE);
            linear_detil.setVisibility(View.GONE);
        }

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_xiadan:
                Intent intent = new Intent(getActivity(), PayLandActivity.class);
                intent.putExtra("act_name",getActivity().getClass().getSimpleName());
                startActivity(intent);
                onBackClick();
                onBackClick();
                break;
        }
    }
}
